<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>String类型</title>
</head>
<body>
<script>
    var num = 10;
    console.log(num.toString()); // "10"
    console.log(num.toString(2)); // "1010"
    console.log(num.toString(8)); // "12"
    console.log(num.toString(10)); // "10"
    console.log(num.toString(16)); // "a"
    var bool = true;
    console.log(bool.toString());  // "true"
    var a = null, b;
    // console.log(a.toString());  // 报错
    // console.log(b.toString());  // 报错
    console.log(String(a));  // "null"
    console.log(String(b));  // "undefined"
    var obj = {
        name: 'tincyho',
        gender: 'male'
    }
    console.log(obj.toString());  // [Object Object]
    console.log(String(obj));  // [Object Object]

    var str = 'Hello world!';
    console.log(str.length);  // 12
    console.log(str.substring(2));  // llo world!
    console.log(str.substring(2, 5));  // llo
    console.log(str.substr(2, 5));  // llo w

    var arr = str.split(''); 
    console.log(arr);  // ["H", "e", "l", "l", "o", " ", "w", "o", "r", "l", "d", "!"]
    console.log(arr.join(','));  // H,e,l,l,o, ,w,o,r,l,d,!

</script>
</body>
</html>